package com.example.demo1;

import com.example.demo1.Demo2.PeopleController;
import com.example.demo1.Demo2.PeopleController2;
import com.example.demo1.Demo2.PeopleController3;
import com.example.demo1.controller.*;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class Demo1Application {

    public static void main(String[] args) {
        //spring上下文
        ApplicationContext context = SpringApplication.run(Demo1Application.class, args);
        //从context中获取bean
        HelloController bean = context.getBean(HelloController.class);
        bean.sayHello();

        //五大注解下一个类型存在多个bean 我们就不能只使用类型来获取，要通过类型加bean名的方式
        /**bean名的命名方式
         * 1.如果没有显示提供bean的名称。spring容器就会给这个bean生成唯一的名称
         * 2.命名约定使用Java标准约定作为实例字段名，也就是说，bean名称以小写字母开头，然后使用驼峰式大小写
         * 比如类名UserController bean名为userController
         * 3.当多个字符并且第一个和第二个字符都是大写时，将保留原始的大小写
         * 比如UController bean名称为UController
         */
        UserInfo userInfo = context.getBean("userInfo3", UserInfo.class);
        System.out.println(userInfo.toString());

        PeopleController peopleController = context.getBean(PeopleController.class);
        peopleController.sayhi();

        PeopleController2 peopleController2 = context.getBean(PeopleController2.class);
        peopleController2.sayhi();

        PeopleController3 peopleController3 = context.getBean(PeopleController3.class);
        peopleController3.sayhi();
    }

}
